package com.jader.adapter;

import java.util.List;

import com.jader.beans.Address;
import com.zlp.jader.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Choice_Address_Adapter extends BaseAdapter {

	private List<Address> list;
	private Context context;
	private LayoutInflater mInflater;
	private ViewHolder viewHolder;
	private int choiceAddressid;

	public Choice_Address_Adapter(List<Address> list, Context context,
			int choiceAddressid) {
		super();
		this.list = list;
		this.context = context;
		this.choiceAddressid = choiceAddressid;
		mInflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.choice_address_adapter, null);
			viewHolder = new ViewHolder();
			viewHolder.address = (TextView) arg1
					.findViewById(R.id.address_save_address);
			viewHolder.phone = (TextView) arg1
					.findViewById(R.id.address_save_userphone);
			viewHolder.savename = (TextView) arg1
					.findViewById(R.id.address_save_username);
			viewHolder.imageView = (ImageView) arg1
					.findViewById(R.id.address_choice_gou);
			arg1.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) arg1.getTag();
		}
		Address address = list.get(arg0);
		if (address.getAddressid() == choiceAddressid) {
			viewHolder.imageView.setImageResource(R.drawable.gou);
		}else {
			viewHolder.imageView.setVisibility(View.INVISIBLE);
		}
		viewHolder.address.setText(address.getProvince() + address.getCity()
				+ address.getArea() + " " + address.getDetail());
		viewHolder.phone.setText(address.getPhone());
		viewHolder.savename.setText(address.getReceiver());
		return arg1;
	}

	class ViewHolder {
		TextView savename, address, phone;
		ImageView imageView;
	}

}
